package com.dcw.lixb.designmode.iterator;

/**
 * @author lixiaobin
 * @date 2020-07-28 14:42:12
 * @desc 描述信息
 */
public class NameRepository implements Container<String> {
    public String[] names = {"张三", "李四", "王五", "赵六"};
    @Override
    public Iterator<String> getIterator() {
        return new NameIterator();
    }

    private class NameIterator implements Iterator<String> {
        int index;
        @Override
        public boolean hasNext() {
            return index < names.length;
        }

        @Override
        public String next() {
            if (hasNext()) {
                return names[index++];
            }
            return null;
        }
    }

}
